package com.yanqingshan.platform.module.sys.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yanqingshan.platform.module.sys.model.domain.SysResource;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 功能描述: 系统资源表 Mapper接口
 *
 * @author yanqs
 * @since 2023-05-15
 */
public interface SysResourceMapper extends BaseMapper<SysResource> {


    @Select("<script>" +
            "SELECT * FROM sys_resource " +
            "where status =0 and " +
            "id IN ( " +
            "SELECT resource_id FROM sys_role_resource WHERE status = 0 AND role_id IN " +
            "(SELECT role_id FROM sys_user_role WHERE status = 0 AND user_id = ${userId} ) " +
            ")" +
            "</script>")
    List<SysResource> listAllResourcesByUserId(@Param("userId") Long userId);


    @Select("<script>" +
            "SELECT resource_key FROM sys_resource " +
            "WHERE status = 0 and type = 'button' and id in( " +
            "SELECT resource_id FROM sys_role_resource WHERE status = 0 and role_id IN(" +
            "SELECT role_id FROM sys_user_role WHERE status = 0 and user_id = ${userId}))" +
            "</script>")
    List<String> listAllPermissionsByUserId(@Param("userId")Long userId);

}
